package com.gs.core.web.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/ahw/")
/*
 * 	What happens if same request mapping is set on 2 different controllers?
	Caused by: java.lang.IllegalStateException: Cannot map handler 'helloWorldController' to URL path [/hw//admin/list]: 
	There is already handler of type [class com.gs.core.web.controllers.AnotherHelloWorldController] mapped.
 * 
 */
		
public class AnotherHelloWorldController {
	
	@RequestMapping("/admin/list")
	public String show(@RequestParam("id") long id,Model model){
		//id is input parameter
		//model is output parameter
		//request gets dispatched to a jsp named helloWorld.jsp
		System.out.println("Got it : " + id+ " using @RequestParam");
		model.addAttribute("id", id+ " using @RequestParam");
		return "helloWorld";
	}
	@RequestMapping("/admin/list/{id}")
	public String showUsingPathVariable(@PathVariable("id") long id,Model model){
		//id is input parameter
		//model is output parameter
		//request gets dispatched to a jsp named helloWorld.jsp
		System.out.println("Got it : " + id + " using @PathVariable");
		model.addAttribute("id", id+ " using @PathVariable");
		return "helloWorld";
	}
	
}
